#ifndef __PROJECT_H__
#define __PROJECT_H__

#include <stdlib.h>
#include "cgic.h"
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <sys/msg.h> 

/*登录结构*/
typedef struct login{
	char name[20];
	char password[7];
	int flags;//记录登录成功与否
} login_t;

/*设备控制结构*/
typedef struct dev_ctrl{
	int led;
	int fan;
	int beep;
} dev_ctrl_t;

/*环境设置结构*/
typedef struct env_set{
	int tmp_up;
	int tmp_dow;
	int hum_up;
	int hum_dow;
	int illu_up;
	int illu_dow;
} env_set_t;

/*环境数据结构 用于向网页发送环境状态*/
typedef struct env_state{
	int tmp;
	int hum;
	int illu;
	int led;
	int fan;
	int beep;
} env_state_t;

/*整体消息结构*/
typedef struct msgbuf { 
	long mtype;
	unsigned int store_num; 
	login_t log_msg;
	env_state_t env_state_msg;
	env_set_t env_set_msg;
	dev_ctrl_t dev_ctrl_msg;
}msg_t;

/*进程同步互斥 信号量*/
union semun{ 
	int val; 
	struct semid_ds *buf; 
	unsigned short *array; 
	struct seminfo *__buf; 
};

void p(int semid,int sem_sum){ 
	struct sembuf sem; 
	sem.sem_num = sem_sum; 
	sem.sem_op = -1; 	//ｐ操作 
	sem.sem_flg = 0; 
	semop(semid,&sem,1); 
}

void v (int semid,int sem_sum){ 
	struct sembuf sem; 
	sem.sem_num = sem_sum; 
	sem.sem_op = 1; 	//V操作 
	sem.sem_flg = 0; 
	semop(semid,&sem,1); 
}

msg_t msg;

int msqid;
int shmid;
/*承接共享内存地址变量*/
msg_t *shm_addr;

#endif
